<!DOCTYPE html>
<html lang="zh-cn">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS020-事件流</title>
</head>
<style>
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    body {
        background-color: #222;
        color: snow;
    }

    .dad {
        position: absolute;
        inset: 2rem;
        background-color: skyblue;
    }

    .son {
        position: absolute;
        inset: 4rem;
        background-color: steelblue;
    }
</style>

<body>
    <div class="dad">
        <div class="son"></div>
    </div>
    <script>
        const dad = document.querySelector('.dad');
        const son = document.querySelector('.son');

        dad.addEventListener('mouseenter', onMouseEnter);

        function onMouseEnter() {
            console.log('mouse entered.');
            //解绑事件，该函数只触发一次
            dad.removeEventListener('mouseenter', onMouseEnter);
        }
    </script>
</body>

</html>